package top.hzy520.log.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import top.hzy520.common.constants.Constants;
import top.hzy520.common.page.Pagination;
import top.hzy520.common.resp.ApiResult;
import top.hzy520.log.entity.SysLoginLog;
import top.hzy520.log.entity.SysOperationLog;
import top.hzy520.log.service.LogService;

import java.util.List;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 10:02 2018/9/20
 */
@RestController
@RequestMapping("log")
public class LogController {
    @Autowired
    @Qualifier("logServiceImpl")
    private LogService logService;
    /**
    *@Author: HouZeYu
    *@Description: 分页查询操作日志信息
    *@Date: 17:03 2018/9/21
    */
    @RequestMapping("/operationlist")
    public Pagination queryOperationLog(int limit, int offset){
        int count=logService.queryOperationLogAllCount();
        List<SysOperationLog> sysOperationLogList=logService.paginationQueryOperationLog(offset,limit);
        Pagination pagination=new Pagination();
        pagination.setTotal(count);
        pagination.setRows(sysOperationLogList);
        return pagination;
    }
    @RequestMapping("/loginlist")
    public Pagination queryLoginLog(int limit, int offset){
       int count=logService.queryLoginLogAllCount();
        List<SysLoginLog> sysLoginLogList=logService.paginationQueryLoginLog(offset,limit);
      Pagination pagination=new Pagination();
      pagination.setTotal(count);
      pagination.setRows(sysLoginLogList);
     return pagination;
    }
    @RequestMapping(value = "/deleteloginlog",method = RequestMethod.POST)
    public ApiResult deleteLoginLog(@RequestBody List<SysLoginLog> loginLogList){
        ApiResult apiResult=new ApiResult(Constants.RESP_STATUS_OK,"删除成功");
         logService.deleteLoginLog(loginLogList);
        return apiResult;
    }
    @RequestMapping(value = "/deleteoperationlog",method = RequestMethod.POST)
    public ApiResult deleteOperationLog(@RequestBody List<SysOperationLog> operationLogList){
        ApiResult apiResult=new ApiResult(Constants.RESP_STATUS_OK,"删除成功");
        logService.deleteOperationLog(operationLogList);
        return apiResult;
    }
}
